//搜索结果节点：个人搜索节点
let SearchResult_PersonNode = function () {
};
SearchResult_PersonNode.prototype.getOneNode = function (data) {
    let div = document.createElement("div");
    div.className = "searchPerson-item item";
    div.innerHTML =
        '<div class="searchPerson-item-img"><img src="' + data.userLogo.thumbUrl + '"></div>' +
        '<a class="searchPerson-item-name">' + data.userName + '</a>';
    return div;
};
//搜索结果：所有搜索中的10个人搜索节点
let SearchResult_ShareOfTenPeople = function () {
};
SearchResult_ShareOfTenPeople.prototype.setOneNode = function (data) {
    return '<div class="searchPerson-item item">' +
        '<div class="searchPerson-item-img"><img src="' + data.userLogo.thumbUrl + '"></div>' +
        '<a class="searchPerson-item-name">' + data.userName + '</a>' +
        '</div>';
};
//实例：搜索结果：结果为空
let SearchResult_EmptyResult = function (word, kind, nodeName) {
    let kindResult = "结果";
    if (kind) {
        kindResult = kind;
    }
    let failFunc=function(){
        document.querySelector("." + nodeName).innerHTML = '<div class="searchResult-null">' +
            '<div class="searchResult-null-text">' +
            '没有找到与<span>' + word + '</span>相关的<span>' + kindResult + '</span>' +
            '</div>' +
            '</div>';
    };
    return {
        failFunc:failFunc
    }
};

/****************搜索结果：分享对象******************/
let adjustShareInfo = function (playNode) {//自适应屏幕
    let nodeArr = playNode,
        dynamicShare = getClass("dynamic-share")[0],
        width,
        length;
    if (dynamicShare.clientWidth > 600) {
        width = (dynamicShare.clientWidth - 24 - 17) / 2;
        length = 2;
    } else {
        width = dynamicShare.clientWidth - 17;
        length = 1;
    }
    for (let i = 0; i < nodeArr.length; i++) {
        if (length === 2 && i === 0) {
            nodeArr[i].style.margin = "0 12px 20px 0";
        } else if (length === 2 && i === 1) {
            nodeArr[i].style.margin = "0 0 20px 12px";
        } else {
            nodeArr[i].style.margin = "0 0 20px 0"
        }
        nodeArr[i].style.width = width + "px";
    }
    setFontSize(nodeArr);
    return length;
};
let adjustPersonResult = function (playNode) {//自适应屏幕
    let nodeArr = playNode,
        pointWidthNode = getClass("searchResult-person")[0],
        width,
        length;
    width = 158;
    if (pointWidthNode.clientWidth === 950) {
        length = 6;
    } else if (pointWidthNode.clientWidth >= 790) {
        length = 5;
    } else if (pointWidthNode.clientWidth >= 632) {
        length = 4;
    } else if (pointWidthNode.clientWidth >= 474) {
        length = 3;
    } else {
        length = 2;
    }
    width = (pointWidthNode.clientWidth) / length;
    for (let i = 0; i < nodeArr.length; i++) {
        nodeArr[i].style.fontSize = "14px";
        nodeArr[i].style.width = width + "px";
    }
    return length;
};
//设置字体
let setFontSize = function (nodeList) {
    let nodeArr = nodeList;
    for (let i = 0; i < nodeArr.length; i++) {
        nodeArr[i].style.fontSize = "14px";
        nodeArr[i].style.padding = "0";
    }
};

/******************左侧模态框显示**********************/
/* 初始函数*/
let fadeM = new fadeModel();
fadeM.checkFade();
fadeM.startMenuShow();
//监视窗口动作
tool.on(window, 'resize', function () {
    fadeM.changeRightPadding();
});

/**
 * 以下为主方法
 **/
let checkWord = function (word) {
    if (!parseURL(window.location.href).params.word) {
        return '" "';
    }
    return word;
};
//当是search_share页时，显示
let ShareResult = function (word) {
    let shareArray = new shareArr();
    shareArray.setPlayNode([getClass("one-cont cont")[0], getClass("two-cont cont")[0]]);
    let url = "/search/share",
        data_send = {
            pageNum: 1,
            pageSize: 10,
            q: word,
            userId: loginUserId
        },
        method = "POST",
        nodeName1 = "dynamic-share",
        nodeName2 = "right-inner",
        lengthToScroll = 0,
        searchResult_EmptyResult = new SearchResult_EmptyResult(checkWord(word), "分享", "dynamic-share");
    MainToPage.setBase(data_send, url, method, "Json");
    MainToPage.setNodeListToShow(shareArray, adjustShareInfo, searchResult_EmptyResult.failFunc);
    MainToPage.setFirstRequest(false);
    MainToPage.setWindowResize(nodeName1);
    MainToPage.setRollWithWindow(nodeName2, nodeName1, lengthToScroll, false);
};
//当是search_person页时，显示
let PersonResult = function (word) {
    let shareArray = new shareArr();
    shareArray.setPlayNode([getClass("searchResultCont")[0], getClass("searchResultCont")[1], getClass("searchResultCont")[2], getClass("searchResultCont")[3], getClass("searchResultCont")[4], getClass("searchResultCont")[5]]);
    shareArray.shareNode = new SearchResult_PersonNode();
    let url = "/search/user",
        data_send = {
            pageNum: 1,
            pageSize: 10,
            q: word,
            userId: loginUserId
        },
        method = "POST",
        nodeName1 = "searchResult-person",
        nodeName2 = "right-inner",
        lengthToScroll = 0,
        searchResult_EmptyResult = new SearchResult_EmptyResult(checkWord(word), "人物", "searchPerson");
    MainToPage.setBase(data_send, url, method, "Json");
    MainToPage.setNodeListToShow(shareArray, adjustPersonResult, searchResult_EmptyResult.failFunc);
    MainToPage.setFirstRequest(false);
    MainToPage.setWindowResize(nodeName1);
    MainToPage.setRollWithWindow(nodeName2, nodeName1, lengthToScroll, false);
};
//当是search_share页时，显示
let AllResult = function (word) {
    //十个分享
    let personArrayNode = {
            pareNode: getClass("searchPerson-inner")[0],
            pointNode: getClass("searchPerson-wrapper")[0],
            pointLeft: getClass("searchPerson-left")[0],
            pointRight: getClass("searchPerson-right")[0]
        },
        tempData = null,
        personArrayNodeLength = 158;
    let scrollPhotoComponent = new ScrollPhotoComponent(personArrayNode);
    let url = "/search/user",
        data_send = {
            pageNum: 1,
            pageSize: 10,
            q: word,
            userId: loginUserId
        },
        method = "POST",
        searchResult_EmptyResult = new SearchResult_EmptyResult(checkWord(word), "人物", "searchPerson-inner");

    ajax_base(data_send, url, method, "Json").then(function (data) {
        if (data && data.obj.length === 0) {
            searchResult_EmptyResult.failFunc();
        }
        scrollPhotoComponent.setOnePhotoNode(new SearchResult_ShareOfTenPeople().setOneNode);
        scrollPhotoComponent.init(personArrayNodeLength, data.obj);
        scrollPhotoComponent.resizeToWindow(false);
    });
    //浏览分享
    ShareResult(word);
};
/*导航条的跳转方法*/
let initToGetInfo = function () {
    let pathList = ["search", "search_share", "search_person"],
        selectKind = new SelectKind(),
        length = 82,
        word = decodeURI(parseURL(window.location.href).params.word);
    if (parseURL(window.location.href).file === "search_share") {
        selectKind.selectByHrefFile(pathList, "search_share", length);
        ShareResult(word);
    } else if (parseURL(window.location.href).file === "search_person") {
        selectKind.selectByHrefFile(pathList, "search_person", length);
        PersonResult(word);
    } else if (parseURL(window.location.href).file === "search") {
        selectKind.selectByHrefFile(pathList, "search", length);
        AllResult(word);
    }
};
initToGetInfo();
